﻿using System;
using Enyim.Caching;
using Ayatta.Contract;
using Web.Base.EventArgs;
using Web.Base.Extensions;
using Web.Base.Controllers;
using Web.Base.GameProxys;
using Web.Base.Models.Game;
using Ayatta.Contract.Component;

namespace Web.Game.Controllers
{
    public abstract class GameBaseController : BaseController
    {
        protected GameBaseController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient)
            : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        protected string GetLoginUri(int gameId, string guid, params string[] param)
        {
            var client = GetGameClient(gameId);
            return client.GetLoginUri(guid, param);
        }

        protected SkResult<UserInfo> GetUser(int gameId, int serverId, string guid, params string[] param)
        {
            var client = GetGameClient(gameId);
            var key = string.Format("Ayatta.Game.UserInfo.{0}.{1}", gameId, guid);
            return Put(key, () => client.GetUser(guid, serverId, param), DateTime.Now.AddMinutes(5));
        }

        protected SkResult<string> CheckUser(int gameId, string guid, params string[] param)
        {
            var client = GetGameClient(gameId);
            return client.CheckUser(guid, param);
        }

    }
}
